1. /* sdoplus.cpp by K.Tsuru */
  2. // function ID = 330 DRADIX
  3. /*********************************
  4. SDouble class
  5. It provides the addition operator+().
  6. It returns m+n.
  7. **********************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. SDouble operator+(const SDouble& m, const SDouble& n){
  12. if((m.Type() != m.REAL)||(n.Type() != n.REAL)) m.SetError(m.RADIX_ERR, "SD +", 330);
  13. int sgn = m.Sign(330) * n.Sign(330);
  14. if(sgn == 0){ //m=0 or n=0
  15. if( m.Sign() == 0 ) return n;
  16. else return m;
  17. } else if (sgn > 0){ //same sign
  18. return DDAdd(m, n);
  19. } else { //different sign
  20. int c = DDCompare(m, n);
  21. // m + n = m -(-n) = n-(-m)
  22. if(c > 0) return DDSub(m, -n); //|m|>|n|, The sign is the same as that of m, set in DDSub()
  23. else if(c) return DDSub(n, -m); //|m|<|n|, sign same as n
  24. else return 0.0; // c = 0 : m = n result = 0
  25. }
  26. }

sdoplus.cpp : last modifiled at 2015/11/25 20:18:04(897 bytes)
created at 2017/10/07 10:21:14
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).